<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>下拉表格组件</title>
    <link rel="icon" th:href="@{/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="ok-body">
            <blockquote class="layui-elem-quote" style="padding: 5px;">
                1.layui第三方扩展组件：<font color="red" size="2">下拉表格(tableSelect)</font>；
                <a href="https://gitee.com/lolicode/layui_component_tableselect" target="_blank" class="layui-btn layui-btn-sm layui-btn-danger">tableSelect</a>
                <br>
                2.本项目暂未用到该组件；
            </blockquote>
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-sm12 layui-col-md6 layui-col-lg6">
                    <pre>
         // Step1. 引入依赖
        let tableSelect = layui.tableSelect;
        <br>

        // Step2. 使用
        tableSelect.render({
            elem: '#demo',                 //定义输入框input对象 必填
            checkedKey: 'id',              //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'keyword',          //搜索输入框的name值 默认keyword
            searchPlaceholder: '关键词搜索', //搜索输入框的提示文字 默认关键词搜索
            table: {                       //定义表格参数，与LAYUI的TABLE模块一致
                url:'',
                cols: [
                        []
                ]
            },
            done: function (elem, data) {
                //选择完后的回调包含2个返回值:elem返回之前input对象；data表格返回的选中的数据
                //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID
            }

        })
                    </pre>
                </div>
                <div class="layui-col-xs12 layui-col-sm12 layui-col-md6 layui-col-lg6">
                    <form class="layui-form" action="" style="padding:20px;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">多选</label>
                            <div class="layui-input-inline">
                                <input type="text" name="" placeholder="请输入" autocomplete="off" class="layui-input" id="demo" value="刘晓军,张恒" ts-selected="002,003">
                            </div>
                            <div class="layui-form-mid layui-word-aux">本地演示数据，分页选中和其他页一样，这不是BUG</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">单选</label>
                            <div class="layui-input-inline">
                                <input type="text" name="" placeholder="请输入" autocomplete="off" class="layui-input" id="demo2">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!--  引入layui框架js文件-->
<script th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" charset="UTF-8"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(["code","form","tableSelect"], function () {
        let code = layui.code;
        let form = layui.form;
        let tableSelect = layui.tableSelect;
        let $ = layui.jquery;

        let ctxPath = /*[[@{/}]]*/'';

        code({
            elem: "pre",
            title: "代码示例",
            encoded: true,
            skin:'notepad', //设置显示风格
            about: false
        });

        //多选
        tableSelect.render({
            elem: '#demo',
            searchKey: 'my',
            checkedKey: 'id',
            searchPlaceholder: '自定义文字和name',
            table: {
                url: ctxPath+'layuimini/api/tableSelect.json',
                cols: [
                    [
                        { type: 'checkbox' },
                        { field: 'id', title: 'ID', width: 100 },
                        { field: 'username', title: '姓名', width: 300 },
                        { field: 'sex', title: '性别', width: 100 }
                    ]
                ]
            },
            done: function (elem, data) {
                let NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.username)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        //单选
        tableSelect.render({
            elem: '#demo2',
            checkedKey: 'id',
            table: {
                url: ctxPath+'layuimini/api/tableSelect.json',
                cols: [
                    [
                        { type: 'radio' },
                        { field: 'id', title: 'ID' },
                        { field: 'username', title: '姓名' },
                        { field: 'sex', title: '性别' }
                    ]
                ]
            },
            done: function (elem, data) {
                let NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.username)
                })
                elem.val(NEWJSON.join(","))
            }
        })
    });
</script>
</body>
</html>
